package com.tbs.parkingsaleapp.Http.Listenner;

import abstergo.tbs.betterasyc.AsycBase.IAsycBackgroundAction;
import abstergo.tbs.betterasyc.AsycBase.IAsycResultAction;
import android.content.Context;
import android.widget.Toast;
import com.tbs.parkingsaleapp.Http.HttpHelper;
import com.tbs.parkingsaleapp.Http.JsonData.OrderInfo;
import com.tbs.parkingsaleapp.SystemManager.NetWorkSetting;
import com.tbs.parkingsaleapp.UI.Adapters.OrderAdapter;

public class CancelOrderHttper implements IAsycBackgroundAction<Integer,Integer>, IAsycResultAction<Integer> {

    private Context context;
    OrderInfo info;
   public CancelOrderHttper(Context context,OrderInfo info)
   {
       this.context=context;
       this.info=info;
   }
    @Override
    public Integer BackGroundAction(Integer... params) throws Exception {
        String r= HttpHelper.Get(NetWorkSetting.CancelOrder(params[0])).trim();
        return Integer.valueOf(r);
    }

    @Override
    public void ResultFunction(Integer result) {

        switch (result)
        {
            case 1:
                Toast.makeText(context,"取消订单成功",Toast.LENGTH_SHORT).show();
                info.getBasic().setStatus(-1);
                OrderAdapter.UpdateItem(info);
                break;
            case 0:
                Toast.makeText(context,"取消失败",Toast.LENGTH_SHORT).show();
                break;
            case -1:
                Toast.makeText(context,"无效订单号",Toast.LENGTH_SHORT).show();
                break;
            case -2:
                Toast.makeText(context,"我们这边出错了",Toast.LENGTH_SHORT).show();
                break;
        }

    }
}